<?php
namespace Ucmaim\Controller\Home;

class HelperController extends CommonController{

    public function Index(){
        // 获取分类信息
        $category = D('ContentCategory')->getCategoryList(0, controller_name());
        $Content  = D('Content');
        $id = (int)I('get.id');
        $cid = (int)I('get.cid');
        $Q   = [];
        // 获取分类内容
        if( !empty($category) ){
            foreach($category as $k => $v) {
                $map['category'] = $v['id'];
                $content_list = $Content->getList($map);
                $category[$k]['list'] = $content_list;
                if( $cid == $v['id'] ){
                    $Q = $content_list;
                }
            }
        }

        if( !empty($Q) && $id > 0 ){
            foreach($Q as $k => $v){
                if( $id == $v['id'] ){
                    $title = $v['title'];
                    $content = htmlspecialchars_decode($v['content']);
                }
            }
        }else{
            $title = $category[0]['list'][0]['title'];
            $content = $category[0]['list'][0]['content'];
        }
        $this->assign('title', $title);
        $this->assign('content', $content);
        $this->assign('category', $category);
        $this->display('Home/Helper');
    }
}